/*     */ package com.feeyin.radar.sys.service.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.Page;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.crm.dao.CustomerDAO;
/*     */ import com.feeyin.radar.crm.dao.CustomerShareDAO;
/*     */ import com.feeyin.radar.crm.dao.SaleRecordDAO;
/*     */ import com.feeyin.radar.crm.model.Customer;
/*     */ import com.feeyin.radar.sys.dao.DepartmentDAO;
/*     */ import com.feeyin.radar.sys.dao.RoleDAO;
/*     */ import com.feeyin.radar.sys.dao.UserDAO;
/*     */ import com.feeyin.radar.sys.model.Department;
/*     */ import com.feeyin.radar.sys.model.Role;
/*     */ import com.feeyin.radar.sys.model.Users;
/*     */ import com.feeyin.radar.sys.service.UserService;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ 
/*     */ public class UserServiceImpl
/*     */   implements UserService
/*     */ {
/*     */   private UserDAO userDAO;
/*     */   private DepartmentDAO departmentDAO;
/*     */   private RoleDAO roleDAO;
/*     */   private CustomerDAO customerDAO;
/*     */   private CustomerShareDAO customerShareDAO;
/*     */   private SaleRecordDAO saleRecordDAO;
/*     */ 
/*     */   public UserDAO getUserDAO()
/*     */   {
/*  36 */     return this.userDAO;
/*     */   }
/*     */ 
/*     */   public void setUserDAO(UserDAO userDAO) {
/*  40 */     this.userDAO = userDAO;
/*     */   }
/*     */ 
/*     */   public DepartmentDAO getDepartmentDAO() {
/*  44 */     return this.departmentDAO;
/*     */   }
/*     */ 
/*     */   public void setDepartmentDAO(DepartmentDAO departmentDAO) {
/*  48 */     this.departmentDAO = departmentDAO;
/*     */   }
/*     */ 
/*     */   public RoleDAO getRoleDAO() {
/*  52 */     return this.roleDAO;
/*     */   }
/*     */ 
/*     */   public void setRoleDAO(RoleDAO roleDAO) {
/*  56 */     this.roleDAO = roleDAO;
/*     */   }
/*     */ 
/*     */   public CustomerDAO getCustomerDAO() {
/*  60 */     return this.customerDAO;
/*     */   }
/*     */ 
/*     */   public void setCustomerDAO(CustomerDAO customerDAO) {
/*  64 */     this.customerDAO = customerDAO;
/*     */   }
/*     */ 
/*     */   public CustomerShareDAO getCustomerShareDAO() {
/*  68 */     return this.customerShareDAO;
/*     */   }
/*     */ 
/*     */   public void setCustomerShareDAO(CustomerShareDAO customerShareDAO) {
/*  72 */     this.customerShareDAO = customerShareDAO;
/*     */   }
/*     */ 
/*     */   public SaleRecordDAO getSaleRecordDAO() {
/*  76 */     return this.saleRecordDAO;
/*     */   }
/*     */ 
/*     */   public void setSaleRecordDAO(SaleRecordDAO saleRecordDAO) {
/*  80 */     this.saleRecordDAO = saleRecordDAO;
/*     */   }
/*     */ 
/*     */   public List getActivityUsersByUserId(Integer userId)
/*     */   {
/*  90 */     if (userId == null) return null;
/*  91 */     Users user = new Users();
/*  92 */     user = this.userDAO.getUser(userId);
/*  93 */     if (user == null) return null;
/*  94 */     String deptIds = "";
/*  95 */     deptIds = this.departmentDAO.getCurrentDeptIdAndSubDeptIdsByDeptId(user.getDeptId());
/*  96 */     if (StringUtils.isEmpty(deptIds)) return null;
/*     */ 
/*  98 */     user = new Users();
/*  99 */     user.setIsActivity("1");
/* 100 */     user.setDeptIds(deptIds);
/*     */ 
/* 102 */     List users = new ArrayList();
/* 103 */     users = this.userDAO.getUsersByDynamic(user);
/* 104 */     if (users == null) return null;
/* 105 */     for (int i = 0; i < users.size(); i++) {
/* 106 */       user = new Users();
/* 107 */       user = (Users)users.get(i);
/* 108 */       Department department = new Department();
/* 109 */       department = this.departmentDAO.getDepartment(user.getDeptId());
/* 110 */       if (department != null) {
/* 111 */         user.setDeptName(department.getDeptName());
/*     */       }
/*     */     }
/* 114 */     return users;
/*     */   }
/*     */ 
/*     */   public List getActivityUsers() {
/* 118 */     List users = new ArrayList();
/* 119 */     users = this.userDAO.getActivityUsers();
/* 120 */     if (users != null) {
/* 121 */       for (int i = 0; i < users.size(); i++) {
/* 122 */         Users user = new Users();
/* 123 */         user = (Users)users.get(i);
/*     */ 
/* 125 */         Department department = new Department();
/* 126 */         department = this.departmentDAO.getDepartment(user.getDeptId());
/*     */ 
/* 128 */         if (department != null) {
/* 129 */           user.setDeptName(department.getDeptName());
/*     */         }
/*     */       }
/*     */     }
/* 133 */     return users;
/*     */   }
/*     */ 
/*     */   public List getPageUsersByDeptIds(Integer deptId, String isActivity, Page page)
/*     */   {
/* 138 */     if ((deptId == null) || (StringUtils.isEmpty(isActivity))) return null;
/* 139 */     if (page == null) return null;
/* 140 */     String deptIds = this.departmentDAO.getCurrentDeptIdAndSubDeptIdsByDeptId(deptId);
/*     */ 
/* 142 */     if (StringUtils.isEmpty(deptIds)) return null;
/* 143 */     List list = new ArrayList();
/* 144 */     list = this.userDAO.getPageUsersByDeptIds(deptIds, isActivity, page);
/* 145 */     if ((list == null) || (list.size() <= 0)) return null;
/*     */ 
/* 147 */     for (int i = 0; i < list.size(); i++) {
/* 148 */       Users user = new Users();
/* 149 */       user = (Users)list.get(i);
/*     */ 
/* 151 */       Department dept = new Department();
/* 152 */       dept = this.departmentDAO.getDepartment(user.getDeptId());
/* 153 */       if (dept != null) {
/* 154 */         user.setDeptName(dept.getDeptName());
/*     */       }
/*     */ 
/* 157 */       Role role = new Role();
/* 158 */       role = this.roleDAO.getRole(user.getRoleId());
/* 159 */       if (role != null) {
/* 160 */         user.setRoleName(role.getRoleName());
/*     */       }
/*     */     }
/*     */ 
/* 164 */     return list;
/*     */   }
/*     */   public Integer getPageUsersCountByDeptIds(Integer deptId, String isActivity) {
/* 167 */     if ((deptId == null) || (StringUtils.isEmpty(isActivity))) return null;
/* 168 */     String deptIds = this.departmentDAO.getCurrentDeptIdAndSubDeptIdsByDeptId(deptId);
/* 169 */     if (StringUtils.isEmpty(deptIds)) return Integer.valueOf(0);
/* 170 */     return this.userDAO.getPageUsersCountByDeptIds(deptIds, isActivity);
/*     */   }
/*     */ 
/*     */   public List getPageUsersByRoleId(Integer roleId, Page page) {
/* 174 */     if ((roleId == null) || (page == null)) return null;
/*     */ 
/* 176 */     List list = new ArrayList();
/* 177 */     list = this.userDAO.getPageUsersByRoleId(roleId, page);
/* 178 */     if ((list == null) || (list.size() <= 0)) return null;
/*     */ 
/* 180 */     for (int i = 0; i < list.size(); i++) {
/* 181 */       Users user = new Users();
/* 182 */       user = (Users)list.get(i);
/*     */ 
/* 184 */       Department dept = new Department();
/* 185 */       dept = this.departmentDAO.getDepartment(user.getDeptId());
/* 186 */       if (dept != null) {
/* 187 */         user.setDeptName(dept.getDeptName());
/*     */       }
/*     */     }
/* 190 */     return list;
/*     */   }
/*     */   public Integer getPageUsersCountByRoleId(Integer roleId) {
/* 193 */     if (roleId == null) return null;
/* 194 */     return this.userDAO.getPageUsersCountByRoleId(roleId);
/*     */   }
/*     */ 
/*     */   public List getUsersByDeptId(Integer deptId) {
/* 198 */     if (deptId == null) return null;
/* 199 */     return this.userDAO.getUsersByDeptId(deptId);
/*     */   }
/*     */ 
/*     */   public List getActivityUsersByDeptIds(String deptIds) {
/* 203 */     if (StringUtils.isEmpty(deptIds)) return null;
/* 204 */     Users user = new Users();
/* 205 */     user.setIsActivity("1");
/* 206 */     user.setDeptIds(deptIds);
/* 207 */     return this.userDAO.getUsersByDynamic(user);
/*     */   }
/*     */ 
/*     */   public Users getUser(Integer id) {
/* 211 */     Users user = new Users();
/* 212 */     user = this.userDAO.getUser(id);
/*     */ 
/* 214 */     if (user == null) return null;
/* 215 */     Department dept = new Department();
/* 216 */     dept = this.departmentDAO.getDepartment(user.getDeptId());
/* 217 */     if (dept != null) {
/* 218 */       user.setDeptName(dept.getDeptName());
/*     */     }
/*     */ 
/* 221 */     Role role = new Role();
/* 222 */     role = this.roleDAO.getRole(user.getRoleId());
/* 223 */     if (role != null) {
/* 224 */       user.setRoleName(role.getRoleName());
/*     */     }
/* 226 */     return user;
/*     */   }
/*     */ 
/*     */   public Users getUserByUserCode(String userCode) {
/* 230 */     return this.userDAO.getUserByUserCode(userCode);
/*     */   }
/*     */ 
/*     */   public Users getUserByUserName(String userName) {
/* 234 */     return this.userDAO.getUserByUserName(userName);
/*     */   }
/*     */ 
/*     */   public Users checkedUser(Users user) {
/* 238 */     if (user == null) return null;
/*     */ 
/* 240 */     Users oldUser = new Users();
/* 241 */     user.setIsActivity("1");
/* 242 */     oldUser = this.userDAO.getUserByDynamic(user);
/* 243 */     if (oldUser == null) {
/* 244 */       user.setUserName(user.getUserCode());
/* 245 */       oldUser = this.userDAO.getUserByDynamic(user);
/*     */     }
/*     */ 
/* 248 */     if (oldUser != null) {
/* 249 */       if (("1".equals(user.getIsUpdatePassword())) || 
/* 250 */         (!StringUtils.isEmpty(user.getNewPassword()))) {
/* 251 */         this.userDAO.updateUserPassword(oldUser.getId(), user.getNewPassword());
/*     */       }
/*     */ 
/* 254 */       Users otherUser = new Users();
/* 255 */       otherUser.setId(oldUser.getId());
/* 256 */       otherUser.setLoginDate(new Date());
/* 257 */       this.userDAO.updateUserByDynamic(otherUser);
/*     */     }
/* 259 */     return oldUser;
/*     */   }
/*     */ 
/*     */   public boolean isRepeatUpdateUserCode(Users user) {
/* 263 */     if (user == null) return false;
/*     */ 
/* 265 */     Users oldUser = new Users();
/* 266 */     oldUser = this.userDAO.getUser(user.getId());
/* 267 */     if (oldUser == null) return false;
/*     */ 
/* 269 */     if (!oldUser.getUserCode().equals(user.getUserCode())) {
/* 270 */       Users otherUser = new Users();
/* 271 */       otherUser = this.userDAO.getUserByUserCode(user.getUserCode());
/* 272 */       if (otherUser != null) return true;
/*     */     }
/* 274 */     return false;
/*     */   }
/*     */ 
/*     */   public boolean isRepeatUpdateUserName(Users user) {
/* 278 */     if (user == null) return false;
/*     */ 
/* 280 */     Users oldUser = new Users();
/* 281 */     oldUser = this.userDAO.getUser(user.getId());
/* 282 */     if (oldUser == null) return false;
/*     */ 
/* 284 */     if (!oldUser.getUserName().equals(user.getUserName())) {
/* 285 */       Users otherUser = new Users();
/* 286 */       otherUser = this.userDAO.getUserByUserName(user.getUserName());
/* 287 */       if (otherUser != null) return true;
/*     */     }
/* 289 */     return false;
/*     */   }
/*     */ 
/*     */   public boolean insertUser(Users user) {
/* 293 */     if (user != null) {
/* 294 */       user.setCreateDate(new Date());
/* 295 */       user.setCreditLevel(Integer.valueOf(3));
/*     */     }
/* 297 */     return this.userDAO.insertUser(user);
/*     */   }
/*     */ 
/*     */   public boolean updateUser(Users user) {
/* 301 */     if (user == null) return false;
/*     */ 
/* 303 */     Users oldUser = new Users();
/* 304 */     oldUser = this.userDAO.getUser(user.getId());
/*     */ 
/* 306 */     boolean result = false;
/* 307 */     result = this.userDAO.updateUser(user);
/*     */ 
/* 309 */     if (oldUser == null) return false;
/* 310 */     if ((result) && (oldUser.getDeptId().compareTo(user.getDeptId()) != 0)) {
/* 311 */       Customer customer = new Customer();
/* 312 */       customer.setSalePersonId(user.getId());
/* 313 */       customer.setCategorys("1,3,5");
/* 314 */       if ("0".equals(user.getIsSaveDept())) {
/* 315 */         List customers = new ArrayList();
/* 316 */         customers = this.customerDAO.getCustomersByDynamic(customer);
/*     */ 
/* 318 */         if (customers != null) {
/* 319 */           customer.setCustomerCategory("2");
/* 320 */           customer.setExceptionReason("2");
/* 321 */           this.customerDAO.updateCustomerByParam(customer);
/*     */ 
/* 324 */           for (int j = 0; j < customers.size(); j++) {
/* 325 */             Customer paramCustomer = new Customer();
/* 326 */             paramCustomer = (Customer)customers.get(j);
/* 327 */             this.customerShareDAO.deleteCustomerShare(paramCustomer.getId());
/* 328 */             this.customerDAO.updateCustomerShare(paramCustomer.getId(), "0");
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/*     */       }
/*     */       else
/*     */       {
/* 336 */         customer.setDeptId(user.getDeptId());
/* 337 */         this.customerDAO.updateCustomerByParam(customer);
/*     */       }
/*     */     }
/*     */ 
/* 341 */     return result;
/*     */   }
/*     */ 
/*     */   public boolean updateUserLastLoginDate(Integer userId) {
/* 345 */     if (userId == null) return false;
/* 346 */     return this.userDAO.updateUserLastLoginDate(userId);
/*     */   }
/*     */ 
/*     */   public boolean stopUsers(String[] ids) {
/* 350 */     if ((ids == null) || (ids.length <= 0)) return false;
/*     */ 
/* 352 */     for (int i = 0; i < ids.length; i++) {
/* 353 */       boolean result = false;
/* 354 */       Users user = new Users();
/* 355 */       user.setId(Integer.valueOf(Integer.parseInt(ids[i])));
/* 356 */       user.setIsActivity("0");
/* 357 */       result = this.userDAO.updateUserByDynamic(user);
/*     */ 
/* 360 */       if (result) {
/* 361 */         List customers = new ArrayList();
/* 362 */         Customer tCustomer = new Customer();
/* 363 */         tCustomer.setSalePersonId(Integer.valueOf(Integer.parseInt(ids[i])));
/* 364 */         tCustomer.setCategorys("1,3,5");
/* 365 */         customers = this.customerDAO.getCustomersByDynamic(tCustomer);
/*     */ 
/* 367 */         if (customers != null) {
/* 368 */           Customer customer = new Customer();
/* 369 */           customer.setSalePersonId(Integer.valueOf(Integer.parseInt(ids[i])));
/* 370 */           customer.setCategorys("1,3,5");
/* 371 */           customer.setCustomerCategory("2");
/* 372 */           customer.setExceptionReason("3");
/* 373 */           this.customerDAO.updateCustomerByParam(customer);
/*     */ 
/* 376 */           for (int j = 0; j < customers.size(); j++) {
/* 377 */             Customer paramCustomer = new Customer();
/* 378 */             paramCustomer = (Customer)customers.get(j);
/* 379 */             this.customerShareDAO.deleteCustomerShare(paramCustomer.getId());
/* 380 */             this.customerDAO.updateCustomerShare(paramCustomer.getId(), "0");
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 389 */     return true;
/*     */   }
/*     */ 
/*     */   public boolean deleteUsers(String[] ids) {
/* 393 */     if ((ids == null) || (ids.length <= 0)) return false;
/*     */ 
/* 395 */     for (int i = 0; i < ids.length; i++) {
/* 396 */       boolean result = false;
/* 397 */       Users user = new Users();
/* 398 */       user.setId(Integer.valueOf(Integer.parseInt(ids[i])));
/* 399 */       user.setIsActivity("2");
/* 400 */       result = this.userDAO.updateUserByDynamic(user);
/*     */ 
/* 403 */       if (result) {
/* 404 */         List customers = new ArrayList();
/* 405 */         Customer tCustomer = new Customer();
/* 406 */         tCustomer.setSalePersonId(Integer.valueOf(Integer.parseInt(ids[i])));
/* 407 */         tCustomer.setCategorys("1,3,5");
/* 408 */         customers = this.customerDAO.getCustomersByDynamic(tCustomer);
/*     */ 
/* 410 */         if (customers != null) {
/* 411 */           Customer customer = new Customer();
/* 412 */           customer.setSalePersonId(Integer.valueOf(Integer.parseInt(ids[i])));
/* 413 */           customer.setCategorys("1,3,5");
/* 414 */           customer.setCustomerCategory("2");
/* 415 */           customer.setExceptionReason("3");
/* 416 */           this.customerDAO.updateCustomerByParam(customer);
/*     */ 
/* 419 */           for (int j = 0; j < customers.size(); j++) {
/* 420 */             Customer paramCustomer = new Customer();
/* 421 */             paramCustomer = (Customer)customers.get(j);
/* 422 */             this.customerShareDAO.deleteCustomerShare(paramCustomer.getId());
/* 423 */             this.customerDAO.updateCustomerShare(paramCustomer.getId(), "0");
/*     */           }
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 431 */     return true;
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.service.impl.UserServiceImpl
 * JD-Core Version:    0.6.0
 */